package Database;

import java.lang.Comparable;
import java.util.Comparator;
import Query.SearchEnginesTypes;

public class Document implements Comparable<Document>, Comparator<Document>
{    
    private String url = null;
    private String title = null;
    private SearchEnginesTypes searchEngine = null;
    private String summary = null;
    private double priority = 0;
    
    public double getPriority()
    {
        return priority;
    }
    
    public void setPriority(double p)
    {
        priority = p;
    }
    
    public Document()
    {
    }
    
    public Document(String url, String title, String summary, SearchEnginesTypes searchEngine) 
    {
        this.url = url;
        this.title = title;
        this.searchEngine = searchEngine;
        this.summary = summary;
    }
    
    public String getUrl()
    {
        return url;
    }
    
    public String getTitle()
    {
        return title;
    }
    
    public String getSummary()
    {
        return summary;
    }
    
    public SearchEnginesTypes getSearchEngine()
    {
        return searchEngine;
    }
    
    public void setUrl(String url)
    {
        this.url = url;
    }
    
    public void setTitle(String title)
    {
        this.title = title;
    }
    
    public void setSummary(String summary)
    {
        this.summary = summary;
    }
    
    public void setSearchEngine(SearchEnginesTypes searchEngine)
    {
        this.searchEngine = searchEngine;
    }
    
    public String toString()
    {
        return getSearchEngine() + " - " + getTitle() + " - " + getSummary() + " << " + getUrl() + " >>";
    }
    
    public int compareTo(Document o)
    {
        /*
        if(this.title.compareTo(o.getTitle()) == 0)
            if(this.url.compareTo(o.getUrl()) == 0)
                return this.searchEngine.compareTo(o.getSearchEngine());
            else
                return this.url.compareTo(o.getUrl());
        else
            return this.title.compareTo(o.getTitle());
         */
        return this.url.compareTo(o.getUrl());
    }

    public int compare(Document o1, Document o2)
    {
        return o1.compareTo(o2);
    }
    
    public boolean equals(Object obj)
    {
        if(!(obj instanceof Document)) return false;
        return this.compareTo((Document)obj) == 0;
    }
}
